package com.xn2001.jpa.controller;

import com.xn2001.jpa.dao.StudentRepository;
import com.xn2001.jpa.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 乐心湖 on 2020/3/7 1:14
 */
@RestController
public class StudentController {

    @Autowired
    private StudentRepository studentRepository;

    @GetMapping("/")
    public List<Student> findAll(){
        return studentRepository.findAll();
    }

    @PostMapping("/")
    public void add(@RequestBody Student student){
        studentRepository.save(student);
    }

    @PutMapping("/")
    public void update(@RequestBody Student student){
        studentRepository.save(student);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable int id){
        studentRepository.deleteById(id);
    }

}
